package com.wyq.jpa.Filter;

import com.wyq.jpa.web.WapperedResponse;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class GavinFilter implements Filter
{

    public void destroy()
    {
        // TODO 自动生成方法存根

    }

    public void doFilter(ServletRequest arg0, ServletResponse arg1,
                         FilterChain arg2) throws IOException, ServletException {
        HttpServletResponse resp=(HttpServletResponse)arg1;
        WapperedResponse wapper=new WapperedResponse(resp);
        arg2.doFilter(arg0, wapper);
        byte[] b1=wapper.getResponseData();
        //do something with b1 here
        //byte[] b2="<?xml version=\"1.0\" encoding=\"UTF-8\"?>".getBytes();
        //输出处理后的数据
        ServletOutputStream output=arg1.getOutputStream();
        output.write(b1);//(new String(b2)+new String(b1)
        output.flush();
    }


    public void init(FilterConfig arg0) throws ServletException
    {
        // TODO 自动生成方法存根

    }

}